package com.tanhua.db.api;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.injector.methods.Update;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tanhua.db.mapper.SoundTimesMapper;
import com.tanhua.dubbo.api.SoundTimesApi;
import com.tanhua.model.pojo.SoundTimes;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class SoundTimesApiImpl implements SoundTimesApi {

    @Autowired
    private SoundTimesMapper soundTimesMapper;

    //根据userId查询
    @Override
    public SoundTimes findById(Long userId) {
        return soundTimesMapper.selectOne(Wrappers.lambdaQuery(SoundTimes.class).eq(SoundTimes::getUserId,userId));
    }

    //重置次数
    @Override
    public void resetTimes(){
        LambdaUpdateWrapper<SoundTimes> wrapper = new LambdaUpdateWrapper<>();
        wrapper.set(SoundTimes::getReceivetimes,10);
        wrapper.set(SoundTimes::getSendtimes,10);
        soundTimesMapper.update(null,wrapper);
    }

    //更新
    @Override
    public void update(SoundTimes soundTimes) {
        soundTimesMapper.updateById(soundTimes);
    }
}
